<!--
    页面：导入导出
    路由：/importSheet
    作者：尹竹群
    部门：查账开发部
    时间：2021-09
    编辑：
-->
<template>
  <div class="container">
    <Row v-tc-height="'100%'">
      <!-- luckysheet表格区域 -->
      <i-col span="21" v-tc-height="'100%'">
        <div class="luckysheet" id="delSheet"></div>
      </i-col>
      <!-- 控制台 -->
      <i-col span="3" v-tc-height="'100%'">
        <Card :bordered="false">
          <p slot="title">控制台</p>
          <p>
            <Row v-tc-bottom="10">
              <Col span="24">
                <Button type="primary" @click="handleDeleteRowColumn('row')"
                  >第二行后删除1行</Button
                >
              </Col>
            </Row>
            <Row v-tc-bottom="10">
              <Col span="24">
                <Button type="primary" @click="handleDeleteRowColumn('column')"
                  >第二列后删除1列</Button
                >
              </Col>
            </Row>
          </p>
        </Card>
      </i-col>
    </Row>
  </div>
</template>

<script>
// 引入loadsh
import { cloneDeep } from "lodash";
// 解析文件插件
import LuckyExcel from "luckyexcel";
import LuckyExport from "./utils/export";

export default {
  name: "delSheet",
  data() {
    return {
      // 表格初始化数据
      sheetData: {
        // 设定DOM容器的id
        container: "delSheet",
        // 是否显示顶部信息栏
        showinfobar: false,
        // 设定表格语言
        lang: "zh",

        // 表格
        data: [
          //数据
          {
            name: "表一", //工作表名称
            color: "",
            index: 0, //唯一id
            status: 1,
            order: 0,
            row: 40, //行数
            column: 40, //列数
            celldata: [
              {
                t: "v",
                v: {
                  v: 233,
                  ct: { fa: "General", t: "n" },
                  m: "233"
                },
                r: 1,
                c: 1
              },
              {
                t: "v1",
                v: {
                  v: 233
                },
                r: 1,
                c: 2
              },
              {
                t: "v2",
                v: {
                  v: 233
                },
                r: 2,
                c: 1
              }
            ],
            config: {},
            allowEdit: false
          },
          {
            name: "表二",
            color: "",
            index: 1,

            status: 0,
            order: 1,
            celldata: [],
            config: {}
          }
        ]
      },
      // 备份数据
      copySheetData: null,
      // 表格数据
      showSheetData: null
    };
  },
  methods: {
    /**
     * 初始化报表
     */
    initSheet() {
      window.luckysheet.create(this.showSheetData);
    },

    /**
     * 删除表格行、列
     * @param {String} type 列或者行
     * @param {Number} number 初始化数量
     */
    handleDeleteRowColumn(type, number = 1) {
      type === "row" && window.luckysheet.deleteRow(1, number);

      type === "column" && window.luckysheet.deleteColumn(1, number);
    }
  },
  mounted() {
    this.showSheetData = cloneDeep(this.sheetData);

    // 初始化报表
    this.initSheet();
  }
};
</script>

<style scoped>
.luckysheet {
  width: 100%;
  height: 100%;
}
</style>
